package com.jh.example;

public class ForOneToHundred41 {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		int toNum = 100;
		try {
			toNum=ScannerInput.readInt();
		} catch (Exception e) {
			System.out.println("잘못된 값이 입력 되었습니다.");
			System.exit(1);
			return;
		}
		
		
		int summs = 0;
		for (int i = 1; i < toNum; i++) 
		{
			summs+=i;
		}
		System.out.printf("1 to %d summation %d",toNum,summs);
		
		//메서드1
		int sum = summation(1,toNum);
		System.out.printf("1 to %d summation %d",toNum,sum);
		
		//메서드2
		int sum2 = summation(toNum);
		System.out.printf("1 to %d summation %d",toNum,sum2);
	}
	
	public static int summation(int start, int end)
	{
		if (start>end) 
		{
			return -1;
		}
		int sum=0;
		for (int i = 0; i < end; i++) 
		{
			sum+=i;
		}
		return sum;
	}
	
	public static int summation(int end)
	{
		return summation(1, end);
	}
}
